package com.centriole.service.workflow.entity;

import com.centriole.common.utils.CommonUtil;
import org.activiti.engine.history.HistoricProcessInstance;
import org.apache.commons.lang.StringUtils;

import java.util.Date;

public class ProInstance extends BaseEntity {

	private static final long serialVersionUID = -2176951063880345780L;

	private String processId;
	private String instanceId;
	/* 该流程实例是在 什么app下 运行，比如： "service-log" */
	private String appName;
	/* 发起流程的用户id */
	private String startUserId;
	private String applyUser;
	private String remark;
	private String fileUrl;
	//破环了封装
	public Date finishTime;
	/* 当前流程的进行状态*/
	private String state;

    /*  已经超时的时间数 */
    private Integer timeOutTime;

	public String getCreateTimeStr(){
		return CommonUtil.getymdhm(getCreateDate());
	}

	public String getProcessId() {
		return processId;
	}
	public void setProcessId(String processId) {
		this.processId = processId;
	}
	public String getInstanceId() {
		return instanceId;
	}
	public void setInstanceId(String instanceId) {
		this.instanceId = instanceId;
	}
	public String getApplyUser() {
		return applyUser;
	}
	public void setApplyUser(String applyUser) {
		this.applyUser = applyUser;
	}
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}
	public String getFileUrl() {
		return fileUrl;
	}
	public void setFileUrl(String fileUrl) {
		this.fileUrl = fileUrl;
	}

	public String getAppName() {
		return appName;
	}

	public void setAppName(String appName) {
		this.appName = appName;
	}

	public String getStartUserId() {
		return startUserId;
	}

	public void setStartUserId(String startUserId) {
		this.startUserId = startUserId;
	}

    public Integer getTimeOutTime() {
        return timeOutTime;
    }

    public void setTimeOutTime(Integer timeOutTime) {
        this.timeOutTime = timeOutTime;
    }

    public String getFinishTime() {
		if(finishTime==null) return null;
		return CommonUtil.getymdhm(finishTime);
	}

	public void setFinishTime(Date finishTime) {
		this.finishTime = finishTime;
	}

	@Override
	public String getState() {
		return state;
	}

	@Override
	public void setState(String state) {
		this.state = state;
	}

	@Override
	public String toString() {
		return "ProInstance [processId=" + processId + ", instanceId=" + instanceId + ", applyUser=" + applyUser
				+ ", remark=" + remark + ", fileUrl=" + fileUrl +  ", finishTime=" + finishTime +"]";
	}

	/**
	 * 转换状态
	 * @return
	 */
	public String convertVoState(){
		if(StringUtils.isBlank(state)) return "-1";
		switch (state){
			case "5":	state="1"; return "1";		//进行中
			case "7":state ="2"; return "2";		//已结束
			default: return "-1";
		}
	}

	public String getStateName(){
		switch (state){
			case "1":return "run";		//进行中
			case "2":return "finished";	//已结束
			default: return "none";
		}
	}

	public String getStateChinese(){
		switch (state){
			case "1":return "进行中";		//进行中
			case "2":return "已结束";	//已结束
			default: return "位置";
		}
	}
}
